package com.wu.llpsw.entity.model;

import com.wu.llpsw.data.playerData;
import com.wu.llpsw.effect.buff.xuanleiduanti;
import com.wu.llpsw.effect.buff.yuanlixuluan;
import net.minecraft.world.damagesource.DamageSource;

import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import com.wu.llpsw.data.levelData;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.SmallFireball;
import net.minecraft.world.entity.projectile.Snowball;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;

public class fireballEntity extends Snowball {
    float attack=1.0f;
    public fireballEntity(Level world, Player player,double x,double y,double z,float attack) {
        super(world,x,y,z);
        //设置不受重力影响
        this.setNoGravity(true);
        //设置该实体不可见
        //this.setInvisible(true);
        //设置发射者
        this.setOwner(player);
        //设置攻击力
        this.attack=attack;
    }

    //击中实体
    @Override
    protected void onHitEntity(EntityHitResult entityHitResult) {
        super.onHitEntity(entityHitResult);
        if (!this.level.isClientSide) {
            Entity entity = entityHitResult.getEntity();
            if (!entity.fireImmune()) {

                entity.getCommandSenderWorld().explode(entity,entity.getX(),entity.getY()+1,entity.getZ(),0, Explosion.BlockInteraction.BREAK);
                Player player = (Player)this.getOwner();
                //造成伤害
                entity.hurt(DamageSource.GENERIC, this.attack);

                //如果被击中的是玩家且等级低于玩家，则可以造成5秒元力絮乱
                if(entity instanceof Player){
                    Player playered=(Player) entity;
                    if(levelData.getLevel(playered.experienceLevel)+3<=levelData.getLevel(player.experienceLevel)){
                        playered.addEffect(new MobEffectInstance(new yuanlixuluan(MobEffectCategory.HARMFUL, 0x000033, false), 20*5, 1));
                    }
                }
            }
        }

    }
}
